<?php
include_once 'mod.php';
$mod = new mod();
if ($_SERVER['REQUEST_METHOD']=='POST'){
    $login_name = $_POST['login_name'];
    $password = $_POST['password'];
    if (empty($login_name)){
        die('用户名不能为空<a href="login.php">重新登录</a>');
    }
    if (empty($password)){
        die('密码不能为空<a href="login.php">重新登录</a>');
    }
    $mysql = $mod->link();
    $sql = "select * from user where `login_name` = '$login_name'";
    $result = $mod->select($mysql,$sql);
    if ($result[0]['password'] == $password){
        setcookie('user',md5($login_name,$password),time()+3600*24,'/');
        session_start();
        $_SESSION['user'] = $_COOKIE['user'];
        die('登陆成功<a href="index.php">前往首页</a>');
    }else{
        die('用户名或者密码错误<a href="login.php">重新登录</a>');
    }
}

?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录</title>
</head>
<body>
<form action="" method="post">
    <p>用户名:<input type="text" name="login_name"></p>
    <p>密码:<input type="password" name="password"></p>
    <input type="submit" value="登录">
    <a href="register">注册</a>
</form>
</body>
</html>
